package models;

import java.io.Serializable;
import javax.persistence.*;

import prefix.util.JPAUtil;

import repository.OrderRepository;

import java.util.Date;

/**
 * The persistent class for the order_detail database table.
 * 
 */
@Entity
@Table(name = "ORDER_DETAIL")
public class OrderDetail implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @TableGenerator(
            name = "ORDER_DETAIL_SEQ",
            table = "SEQUENCE",
            pkColumnName = "NAME",
            pkColumnValue = "ORDER_DETAIL_SEQ",
            valueColumnName = "CNT",
            initialValue = 10000,
            allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "ORDER_DETAIL_SEQ")
    @Column(unique = true, nullable = false)
    private Integer id;

    private double amount;
    
    @Column(name="ACCRUE_AMOUNT")
    private double accrueAmount;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "BUD_D")
    private Date budD;

    @Column(name = "BUY_PRICE")
    private double buyPrice;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "CREATE_D")
    private Date createD;

    @Column(name = "LOAN_ID")
    private Integer loanId;

    @Column(name = "ORDER_ID")
    private Integer orderId;

    @Column(name = "RECEIVED_INT")
    private double receivedInt;

    @Column(name = "RECEIVED_LATE_FEE")
    private double receivedLateFee;

    @Column(name = "RECEIVED_PRNCP")
    private double receivedPrncp;

    @Column(name = "SELL_PRICE")
    private double sellPrice;

    private int status;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "STATUS_D")
    private Date statusD;

    private int type;
    
    @Column(name="RPA")
    private Double RPA;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "UPDATE_D")
    private Date updateD;

    public OrderDetail() {
        this.setType(Type.DEFAULT);
        this.setStatus(Status.PENDING);
        this.statusD = new Date();
        this.createD = new Date();
    }

    public Order getOrder() {
        if (this.getOrderId() != null)
            return JPAUtil.em().find(Order.class, this.getOrderId());
        else
            return null;
    }

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public double getAmount() {
        return this.amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public Date getBudD() {
        return this.budD;
    }

    public void setBudD(Date budD) {
        this.budD = budD;
    }

    public double getBuyPrice() {
        return this.buyPrice;
    }

    public void setBuyPrice(double buyPrice) {
        this.buyPrice = buyPrice;
    }

    public Date getCreateD() {
        return this.createD;
    }

    public void setCreateD(Date createD) {
        this.createD = createD;
    }

    public Integer getLoanId() {
        return this.loanId;
    }

    public void setLoanId(Integer loanId) {
        this.loanId = loanId;
    }

    public double getReceivedInt() {
        return this.receivedInt;
    }

    public void setReceivedInt(double receivedInt) {
        this.receivedInt = receivedInt;
    }

    public double getReceivedLateFee() {
        return this.receivedLateFee;
    }

    public void setReceivedLateFee(double receivedLateFee) {
        this.receivedLateFee = receivedLateFee;
    }

    public double getReceivedPrncp() {
        return this.receivedPrncp;
    }

    public void setReceivedPrncp(double receivedPrncp) {
        this.receivedPrncp = receivedPrncp;
    }

    public double getSellPrice() {
        return this.sellPrice;
    }

    public void setSellPrice(double sellPrice) {
        this.sellPrice = sellPrice;
    }

    public Status getStatus() {
        return Status.values()[this.status];
    }

    public void setStatus(Status status) {
        this.status = status.ordinal();
    }

    public Date getStatusD() {
        return this.statusD;
    }

    public void setStatusD(Date statusD) {
        this.statusD = statusD;
    }

    public Type getType() {
        return Type.values()[this.type];
    }

    public void setType(Type type) {
        this.type = type.ordinal();
    }

    public Date getUpdateD() {
        return this.updateD;
    }

    public void setUpdateD(Date updateD) {
        this.updateD = updateD;
    }

    public Integer getOrderId() {
        return orderId;
    }

    public void setOrderId(Integer orderId) {
        this.orderId = orderId;
    }

    public Double getRPA() {
        return RPA;
    }

    public void setRPA(Double rPA) {
        RPA = rPA;
    }



    public double getAccrueAmount() {
        return accrueAmount;
    }

    public void setAccrueAmount(double accrueAmount) {
        this.accrueAmount = accrueAmount;
    }



    public static enum Status {
        PENDING, // 0 - lender sbumited the LP
        ISSUED, // 1 - loan issued and thus lender actually bought the LPD's
        EXPIRED, // 2 - loan canceled, money released back to lender
        SOLD, // 3 - loan sold on the secondary market
        MOVED, // 4 - loan sold on the secondary market
        ;
    }

    public enum Type {
        DEFAULT;// 0
    }

}